from rest_framework import serializers

from gesture_demo_server.models import DbCourse, User, DbCourseVideo, UserToken, DbCourseType


class UserSerializer(serializers.ModelSerializer):
    """ 用户信息序列化器 """

    class Meta:
        model = User
        fields = ['id', 'username', 'password', 'sex', 'tel', 'email', 'nickname']
        extra_kwargs = {
            # 'id': {'required': False},
            # "course_title": {"error_messages": {"required": "课程标题不能不填"}}
            # extra_kwargs = {"username": {"error_messages": {"required": "Give yourself a username"}}}
        }


class TeacherSerializer(serializers.ModelSerializer):
    """ 用户信息序列化器 """

    class Meta:
        model = User
        fields = ['id', 'sex', 'tel', 'email', 'nickname']
        extra_kwargs = {
            # 'id': {'required': False},
            # "course_title": {"error_messages": {"required": "课程标题不能不填"}}
            # extra_kwargs = {"username": {"error_messages": {"required": "Give yourself a username"}}}
        }


class CourseVideoSerializer(serializers.ModelSerializer):
    """ 课程视频序列化器 """

    class Meta:
        model = DbCourseVideo
        fields = ['id', 'course', 'video_link', 'video_title', 'video_order']


class CourseSerializer(serializers.ModelSerializer):
    """ 课程信息序列化器 """
    course_videos = CourseVideoSerializer(many=True, read_only=True)

    class Meta:
        model = DbCourse
        fields = ['id', 'type', 'course_title', 'course_des', 'course_cover', 'teacher',
                  'course_videos']
        # extra_kwargs = {
        #     'teacher_info': TeacherSerializer(read_only=True)
        # }


class CourseTypeSerializer(serializers.ModelSerializer):
    """ 课程类型序列化器 """

    class Meta:
        model = DbCourseType
        fields = ['id', 'type']


class UserTokenSerializer(serializers.ModelSerializer):
    """ 用户令牌序列化器 """

    class Meta:
        model = UserToken
        fields = ['id', 'token', 'user']

    @classmethod
    def get_model(cls):
        return UserToken
